package com.ibeetl.admin.api.service;

import com.ibeetl.admin.api.dao.TravelAttractionsDao;
import com.ibeetl.admin.api.dao.TravelAudioDao;
import com.ibeetl.admin.api.dao.TravelPictureDao;
import com.ibeetl.admin.api.dao.TravelVideoDao;
import com.ibeetl.admin.api.entity.Travel_attractions;
import com.ibeetl.admin.core.service.CoreBaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class TravelAttractionsService extends CoreBaseService<Travel_attractions> {
    @Resource
    private TravelAttractionsDao travelAttractionsDao;
    @Resource
    private TravelAudioDao travelAudioDao;
    @Resource
    private TravelPictureDao travelPictureDao;
    @Resource
    private TravelVideoDao travelVideoDao;
    @Resource
    private FileService fileService;
    public List<Travel_attractions> queryByUserId(Long userId) {
        List<Travel_attractions> list = travelAttractionsDao.queryByUserId(userId);
        return  list;
    }

    public void delete(long attsId,int flag) {
        if(flag == 0){
            travelAttractionsDao.updateState(attsId,3,new Date());
        }
        if(flag == 1){
            // 查询所有文件路径   语音   视频   图片
            List<String> paths = travelAttractionsDao.queryAllFilePath(attsId);
            // 删除文件
            //1 删除语音
            //2 删除视频
            //3 删除图片
            if(paths != null && paths.size()>0){
                for(String path : paths){
                    fileService.delete(path);
                }
                //删除记录 语音   视频  图片
                travelAudioDao.deleteByAttsId(attsId);
                travelPictureDao.deleteByAttsId(attsId);
                travelVideoDao.deleteByAttsId(attsId);

            }
            //删除记录 景点
            travelAttractionsDao.deleteById(attsId);

        }
    }

    public long queryNewIdByUserId(Long user_id) {
        List<Long> list = travelAttractionsDao.queryNewIdByUserId(user_id);
        return list.get(0);
    }

    public List<Travel_attractions> queryByAttractionId(Long attractionId) {
        List<Travel_attractions> list = travelAttractionsDao.queryByAttractionId(attractionId);
        return  list;
    }
}
